<!DOCTYPE html>
<html xmlns="https://www.thymeleaf.org">
<head>
<meta charset="UTF-8">
<title>创建试卷</title>
</head>
<body>

	<h2>创建试卷-AJAX提交表单,以默认x-www-form-urlencoded的方式</h2>
	<form id="form2" action="/paper/save" method="post">
		<div>试卷名：<input type="text" name="name"></div>
		<div>试卷题数：<input type="text" name="questionNums"/></div>
		<div>考试时间：<input type="text" name="examTime"/></div>
		<div><input type="submit" value="提交" id="submit2"/></div>
	</form>
	
	<h2>上传图片</h2>
	<form id="form4">
		<div>选择图片：<input type="file" name="file" /></div>
		<div><input type="button" value="提交" id="submit4" /></div>
	</form>
	<div id="info"></div>
	
	<p th:text="${#httpServletRequest.getServletContext().getRealPath('/')}"/>
	
	<script src="http://libs.baidu.com/jquery/2.0.0/jquery.min.js"></script>
	<script type="text/javascript">
	$(function(){
		$('#submit4').click(function(){
			var formData = new FormData($("#form4")[0]);   //内置的浏览器对象
			$.ajax({
				   type: "POST",
				   url: "/paper/upload",
				   data: formData,
				   processData:false,  //不把数据转成x-www-form-urlencoded的格式
				   contentType:false,
				   dataType: 'json',
				   success: function(msg){
					   if(msg.code==200) {location.href="/";}else{$("#info").html(msg.message);}
				   }
			});
		});
	});
	</script>
</body>
</html>